﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Collections;
using Commonlib;
namespace AlbonWeb.Manager.OrderManager
{
    public partial class ShipMent : System.Web.UI.Page
    {
        BLL.ShipBLL shipbll = new BLL.ShipBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            //刷新当前页
            ViewState["Current"] = Request.UrlReferrer.ToString();
            if (!IsPostBack)
            {
                //返回上一页
                ViewState["Back"] = Request.UrlReferrer.ToString();
                bindOrderItem();
            }
        }
        //绑定需要发货的订单项
        private void bindOrderItem()
        {
            string idlist = "0";
            if (Request["orderid"] != null)
            {
                idlist = Request["orderid"].ToString();
            }
            else { 
                ArrayList shipcart=(ArrayList)Session["shipcart"];
                for (int i = 0; i < shipcart.Count; i++)
                {
                    idlist += "," + shipcart[i];
                }
            }
            repMain.DataSource=shipbll.getItemShipView(idlist);
            repMain.DataBind();
        }

        //Ship
        protected void btnShip_Click(object sender, EventArgs e)
        {
            string idlist = hfchecklist.Value;
            foreach (string orderitemid in idlist.Split(','))
            {
                Albon.Model.ShipMent shipment = new Albon.Model.ShipMent();
                shipment.orderItemID =int.Parse(orderitemid);
                shipment.shipCompany = ddlShipCompany.SelectedItem.Value;
                shipment.shipNo = trackNo.Text.Trim();
                shipment.adder = User.Identity.Name;
                shipment.remark = remark.InnerText.Trim();
                shipbll.addShipMent(shipment);
                Response.Redirect(ViewState["Current"].ToString());
            }
        }
        //Back
        protected void btnBack_Click(object sender, EventArgs e)
        {
            Response.Redirect(ViewState["Back"].ToString());
        }
    }
}